function defineLazyProperty(object, propertyName, valueGetter) {
    function define(value) {
        debugger;
        Object.defineProperty(object, propertyName, {
            value,
            enumerable: true,
            writable: true,
        });
    }

    Object.defineProperty(object, propertyName, {
        configurable: true,
        enumerable: true,
        get() {
            debugger;
            const result = valueGetter();
            define(result);
            return result;
        },
        set(value) {
            define(value);
        },
    });

    return object;
}

const unicorn = {};

defineLazyProperty(unicorn, 'rainbow', () => 42);

debugger;
console.log(unicorn.rainbow);
debugger;
console.log(unicorn.rainbow);
